home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / lists / mint / l_1199 / 1195 < prev    next >
Encoding:
Internet Message Format  |  1994-08-27  |  1.8 KB

  1. From: miff@asharak.apana.org.au (michael smith)
  2. Subject: Re: load average patches for MiNT 1.10 + patches
  3. Date: Thu, 10 Mar 94 09:52:34+1030
  4. In-Reply-To: <2d7f745a1e7e81@anuurn.do.open.de> from "Martin Koehling" at Thu, 10 Mar 1994 20:25:14 MEZ
  5. Message-Id: <Up-ECKKAIXO@asharak.apana.org.au>
  6. Mime-Version: 1.0
  7. X-Software: Atari UUCP  UPoint light  (22. Jan. '94)
  8.  
  9. In <2d7f745a1e7e81@anuurn.do.open.de> you wrote :
  10.  
  11. >>michael smith writes:
  12. >>>  but I don't believe in that sort
  13. >>> of ceiling regardless of how it's implemented, and someone is _bound_ to harp
  14. >>> on it.)
  15. >>
  16. >> true.  thats also why you should always do timeouts checks like this
  17. >>
  18. >>    unsigned tick = timer counter (like _hz_200) + time to wait;
  19. >>    for (...)
  20. >>         if (timer counter - tick > 0)  break;
  21. >>
  22. >>instead of
  23. >>    ...
  24. >>         if (timer counter > tick)  break;
  25. >>
  26. >>(and any compiler that `optimizes' the difference away should be shot. :)
  27. >
  28. >I don't quite see the difference between these two checks - they _both_
  29. >will come into trouble if `counter + time to wait' exceeds the value range
  30. >of `unsigned'!
  31. >The only *real* solution I can see is expanding the timer to a `long
  32. >long'...
  33.  
  34.  
  35. No, there is an easier way... (I use it a lot because most microcontrollers
  36. don't have large registers 8)
  37.  
  38.     old_counter = counter++;
  39.     if (counter < old_counter)                                /* wrap condition */
  40.         last_match = MAX_SIGNED_LONG - last_match;    /* result is -ve */
  41.  
  42.     if (counter > (last_match + increment))            /* next event */
  43.     {
  44.         ...
  45.  
  46. Note that the old_counter, counter and last_match need to be signed values.
  47.  
  48. >Martin
  49.  
  50.  
  51. --
  52. --
  53. mike smith : silicon grease monkey  | If you think it can't be done, |
  54. miff@asharak.apana.org.au           | it means you don't have enough |
  55. miff@apanix.apana.org.au            | money in your budget.          |
  56.  
  57.